package com.potenza.training.dictionary.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.dictionary.dao.HopeAddressDao;
import com.potenza.training.dictionary.entity.HopeAddress;
import com.potenza.training.dictionary.server.HopeAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("hopeAddressService")
public class HopeAddressServiceImpl extends ServiceImpl<HopeAddressDao, HopeAddress> implements HopeAddressService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private HopeAddressDao hopeAddressDao;

    @Override
    public List<HopeAddress> findAll() {
        Object hopeAddress = redisTemplate.opsForValue().get("hopeAddress");
        if (hopeAddress==null){
            List<HopeAddress> list = this.list();
            redisTemplate.opsForValue().set("hopeAddress", list);
            return list;
        }
        return (List<HopeAddress>)hopeAddress;
    }

    @Override
    public HopeAddress findById(String id) {
        return hopeAddressDao.selectById(id);
    }
}